<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>编辑关键字</title>
    <link rel="stylesheet" href="__ADMIN_STATICS__/bootstrap/dist/css/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/animate.css/animate.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/font-awesome/css/font-awesome.min.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/simple-line-icons/css/simple-line-icons.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/bootstrap-editable/css/bootstrap-editable.min.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/app/css/font.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/app/css/app.css" type="text/css" />
    <webuploadercss/>
    <link rel="stylesheet" href="__ADMIN_STATICS__/jquery-ui.css">
</head>
<body>
<div class="wrapper-md">
    <div class="panel panel-default">
        <div class="panel-heading">
            <a href="{:U('Admin/Index/index')}"><i class="fa fa-home"></i>&nbsp;首页</a>&nbsp;&gt;<a href="{:U('Admin/WeiXin/index')}">&nbsp;&nbsp;微信关键字列表&nbsp;</a>&gt;&nbsp;&nbsp;关键字
        </div>
        <div class="table-responsive">
            <form class="form-horizontal" action="{:U('Admin/WeiXin/editkw')}" method="post">
                <input type="hidden" name="id" value="{$data['id']}">
                <div class="line line-dashed b-b line-lg pull-in"></div>
                <div class="form-group m-b-none m-l-none m-r-none">
                    <label class="col-sm-2 control-label" for="input-id-1">回复类型：</label>
                    <div class="col-sm-6">
                        <select class="input-sm form-control w-sm inline v-middle m-r" name="type">
                            <option value="1" <if condition="$data['type'] eq 1">selected</if>>文本消息</option>
                            <option value="2" <if condition="$data['type'] eq 2">selected</if>>图片消息</option>
                            <option value="3" <if condition="$data['type'] eq 3">selected</if>>语音消息</option>
                            <option value="4" <if condition="$data['type'] eq 4">selected</if>>视频消息</option>
                            <option value="5" <if condition="$data['type'] eq 5">selected</if>>音乐消息</option>
                            <option value="6" <if condition="$data['type'] eq 6">selected</if>>图文消息</option>
                            <option value="7" <if condition="$data['type'] eq 7">selected</if>>退出当前菜单</option>
                            <option value="8" <if condition="$data['type'] eq 8">selected</if>>应用接口</option>
                        </select>
                    </div>
                </div>

                <div class="line line-dashed b-b line-lg pull-in"></div>
                <div class="form-group m-b-none m-l-none m-r-none">
                    <label class="col-sm-2 control-label" for="input-id-1">上级目录：</label>
                    <div class="col-sm-6">
                        <select class="input-sm form-control w-sm inline v-middle m-r" name="pid">
                            <option value="0">无</option>
                            <volist name="kw" id="c">
                                <option value="{$c['id']}" <if condition="$data['pid'] eq $c['id']">selected</if>>{$c['_name']}</option>
                            </volist>
                        </select>
                    </div>
                </div>

                <div class="line line-dashed b-b line-lg pull-in"></div>
                <div class="form-group m-b-none m-l-none m-r-none">
                    <label class="col-sm-2 control-label" for="input-id-1">是否可见：</label>
                    <div class="col-sm-6">
                        <div class="radio">
                          <label class="i-checks i-checks-sm">
                            <input type="radio" name="is_use" value="1" <if condition="$data['is_use'] eq 1">checked</if>>
                            <i></i>
                            是
                          </label>
                           <label class="i-checks i-checks-sm">
                            <input type="radio" name="is_use" value="2" <if condition="$data['is_use'] eq 2">checked</if>>
                            <i></i>
                            否
                          </label>
                        </div>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg pull-in"></div>
                <div class="form-group m-b-none m-l-none m-r-none">
                    <label class="col-sm-2 control-label" for="input-id-1">功能菜单：</label>
                    <div class="col-sm-6">
                        <div class="radio">
                          <label class="i-checks i-checks-sm">
                            <input type="radio" name="is_parent" value="1" <if condition="$data['is_parent'] eq 1">checked</if>>
                            <i></i>
                            是
                          </label>
                           <label class="i-checks i-checks-sm">
                            <input type="radio" name="is_parent" value="2" <if condition="$data['is_parent'] eq 2">checked</if>>
                            <i></i>
                            否
                          </label>
                        </div>
                        <span class="help-block m-b-none">当目录不存在下级菜单时，请选择否</span>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg pull-in"></div>
                <div class="form-group m-b-none m-l-none m-r-none">
                    <label class="col-sm-2 control-label" for="input-id-1">关键字：</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" name="keyword" value="{$data['keyword']}">
                    </div>
                </div>

                <div id="reply-text" class="reply <if condition="$data[type] neq 1"> hidden</if>">
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">内容：</label>
                        <div class="col-sm-6">
                           <textarea class="form-control" name="content" rows="3">{$data['content']}</textarea><span>限100字</span>
                        </div>
                    </div>
                </div>
                

                <div id="reply-img" class="reply <if condition="$data[type] neq 2"> hidden</if>">
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">url</label>
                        <div class="col-sm-6">
                           <img src="{$data['url']}" height="150" width="auto">
                        </div>
                    </div>                                                 
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">上传url：</label>
                        <div class="col-sm-6">
                           <!-- 上传组件容器 开始-->
                            <div id="pic_upload" class="xb-uploader">
                                <div class="queueList">
                                    <div class="placeholder">
                                        <div class="filePicker"></div>
                                        <p>选择url</p>
                                    </div>
                                </div>
                                <div class="statusBar" style="display:none;">
                                    <div class="progress">
                                        <span class="text">0%</span>
                                        <span class="percentage"></span>
                                    </div>
                                    <div class="info"></div>
                                    <div class="btns">
                                        <div class="uploadBtn">开始上传</div>
                                    </div>
                                </div>
                                <div class="attachment_list" style="display: none;">
                                    <input name="url" type="hidden" value="{$data['url']}" />
                                </div>
                            </div>
                            <!-- 上传组件容器 结束-->
                        </div>
                    </div>
                </div>
                <div id="reply-news" class="reply <if condition="$data[type] neq 6"> hidden</if>">
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">文章：</label>
                        <div class="col-sm-8">
                            <div class="new-container m-b"></div>
                            <input type="text" class="form-control" id="content-news" placeholder="请在此输入您要发表的文章内容" />
                            <input type="hidden" class="form-control" name="values" value=""/>
                        </div>
                    </div>
                </div>
                <div id="reply-interface" class="reply <if condition="$data[type] neq 8"> hidden</if>">
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">接口：</label>
                        <div class="col-sm-6">
                            <select class="input-sm form-control w-sm inline v-middle m-r" name="app_name">
                                <option>请选择</option>
                                <option value="searchDomain" <if condition="$data['app_name'] eq 'searchDomain'">selected</if>>域名查询</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="line line-dashed b-b line-lg pull-in"></div>                    
                <div class="form-group m-l-none m-r-none">  
                    <div class="col-sm-4 col-sm-offset-2">
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="__ADMIN_STATICS__/jquery/jquery.min.js"></script>
<script src="__ADMIN_STATICS__/bootstrap/dist/js/bootstrap.js"></script>
<script src="__ADMIN_STATICS__/webuploader-0.1.5/webuploader.js"></script>
<script src="__ADMIN_STATICS__/webuploader-0.1.5/uploaderSf.js"></script>  

<script src="__ADMIN_STATICS__/jquery-ui.js"></script>
<script type="text/javascript">
$('select[name="type"]').change(function(){
    var type = $(this).val();
    $('.reply').addClass('hidden');
    if(type==1){
        $('#reply-text').removeClass('hidden');
    }else if(type==2){
        $('#reply-img').removeClass('hidden');
    // }else if(type==3){
    //     $('#reply-img').removeClass('hidden');
    // }else if(type==4){
    //     $('#reply-img').removeClass('hidden');
    // }else if(type==5){
    //     $('#reply-img').removeClass('hidden');
    }else if(type==6){
        $('#reply-news').removeClass('hidden');
    }else if(type==7){
        $('#reply-text').removeClass('hidden');
    }else if(type==8){
        $('#reply-interface').removeClass('hidden');
    }
});
$('#pic_upload').sfUpload({
    url:"{:U('Admin/Ad/ajax_upload')}",
    picker:'pic_upload',
    multiple:false,
    sizeLimit:1,
    success:function( data ) {
        $("input[name='url']").val(data.path);
        console.log(data);
    },
    error:function( err ) {
        console.info( err );    
    }
});


var news= {$vData};
// var news= {$vData};

function deleteNews(id){
    var temp = [];
    for(var i=0;i<news.length;i++){
        if(news[i].id==id){
            continue;
        }
        temp.push({id:news[i].id,title:news[i].title});
    }
    news = temp;
    setNewsIds();
    showNews()
}
function setNewsIds(){
    var ids = '';
    for(var i=0;i<news.length;i++){
        ids += news[i].id;
        if(i<news.length-1){
            ids+=',';
        }
    }
    $('input[name="values"]').val(ids);
}
function setHeaderNews(id){
    var temp = [];
    for(var i=0;i<news.length;i++){
        if(news[i].id==id){
            temp.push({id:news[i].id,title:news[i].title});
        }
    }
    for(var i=0;i<news.length;i++){
        if(news[i].id==id){
            continue;
        }
        temp.push({id:news[i].id,title:news[i].title});
    }
    news = temp;
    showNews();
}
function split(val) {
    return val.split(/,\s*/);
}
function extractLast(term){
    return split(term).pop();
}

function showNews(){
    var html = '';
    for(var i=0;i<news.length;i++){
        html += '<div class="input-group m-b news'+news[i].id+'">'+
            '<input type="text" class="form-control" readonly value="'+news[i].title+'">';
        if(i!=0){
            html +='<span class="input-group-btn">'+
            '    <button class="btn btn-success" type="button" onclick="setHeaderNews('+news[i].id+')">头</button>'+
            '</span>';
        }
        html +='<span class="input-group-btn">'+
            '    <button class="btn btn-danger" type="button" onclick="deleteNews('+news[i].id+')">删</button>'+
            '</span>'+
        '</div>';
    
    }
    $('.new-container').html(html);
    setNewsIds();
}

$( "#content-news" )
  // 当选择一个条目时不离开文本域
  .bind("keydown", function( event ) {
    if ( event.keyCode === $.ui.keyCode.TAB &&
        $( this ).data( "ui-autocomplete" ).menu.active ) {
        event.preventDefault();
    }
  })
  .autocomplete({
    source: function( request, response ) {
    $.getJSON( "/index.php?m=Admin&c=article&a=search", {word: extractLast(request.term)},response);},
    search: function() {
        // 自定义最小长度
        var term = extractLast( this.value );
        if ( term.length < 1 ) {return false;}
    },
    focus: function() {
        // 防止在获得焦点时插入值
        return false;
    },
    select: function( event, ui ) {
        var terms = split(this.value);
        // 移除当前输入
        terms.pop();
        // 添加被选项
        terms.push(ui.item.title);
        // 添加占位符，在结尾添加逗号+空格
        terms.push("");
        //this.value = terms.join(", ");
        var isRepeat = false;
        for(var i=0;i<news.length;i++){
            if(news[i].id==ui.item.id){
                isRepeat = true;
                break;
            }
        }
        if(!isRepeat){
            news.push({id:ui.item.id,title:ui.item.title});
        }
        showNews();
        this.value = "";
        return false;
    }
  });
$(function(){
    if(news.length>0){
        showNews();
    }
});
</script>
</body>
</html>